﻿function initBootGrid() {
    $("#grid-data").bootgrid({
        ajax: true,
        url: urlFiles,
        formatters: {
            "link": function (column, row) {
                return getColumn(column, row);
            }
        },
        labels: {
            noResults: "Ningún archivo adjuntado",
            infos: "Mostrando del {{ctx.start}} al {{ctx.end}} de {{ctx.total}} archivos(s)",
            loading: "Cargando",
            refresh: "Actualizar",
            search: "Buscar"
        },
        navigation: 0,
        rowCount: -1
    });
    $("#grid-data").bootgrid()
    .on("loaded.rs.jquery.bootgrid", function (e) {
        $('.CommentHistory').bind('click', function () {
            var windowHeight = $(window).height();
            var url = urlEditions;
            $("#modalFileEditions").load(url, { listId: listId, columnId: columnId, fileName: $(this).data('filename') }, function () {
                $("#modalFileEditions").find('.modal-content').css('max-height', (windowHeight / 2).toString() + 'px');
                $("#modalFileEditions").modal();
            });
        });

        $('.remove-file').bind('click', function () {
            if ($(this).text() !== '¿Confirmar?') {
                $(this).html('¿Confirmar?');
                var button = $(this);
                setTimeout(function () {
                    console.log(button.html());
                    button.html('<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>');
                }, 1000);
                return false;
            }
            else {
                $.post("/EVirtual/RemoveFile", { listId: listId, columnId: columnId, mask: $(this).data('mask') }).always(function (data) {
                    if (data.status == true)
                        $('#grid-data').bootgrid('reload');
                    else
                        $('#error-message').removeClass('hidden');
                });
            }
        });
    });

    $('#modalFileEditions').on('hide.bs.modal', function (e) {
        $("#modalUploadFile").modal('hide');
    });
}

$(function () {
        initBootGrid();   
});